import { user, User } from '@/db/schema';
import { neon } from '@neondatabase/serverless';
// import { drizzle } from 'drizzle-orm/postgres-js';
// import postgres from 'postgres';
// import { eq } from 'drizzle-orm';
import { drizzle } from 'drizzle-orm/neon-http';
import { eq } from 'drizzle-orm/sql/expressions/conditions';
async function getData() {
  const sql = neon(process.env.DATABASE_URL||'');
  const response = await sql`SELECT version()`;
  return response[0].version;
}

// const client = postgres(process.env.DATABASE_URL!);
// const db = drizzle(client);

export async function getUser(email: string): Promise<Array<User>> {
  const sql = neon(process.env.DATABASE_URL!);
  const db = drizzle({ client: sql });
  try {
    return await db.select().from(user).where(eq(user.email, email));
  } catch (error) {
    console.error('Failed to get user from database');
    throw error;
  }
}

export default async function Page() {
  const data = await getData();
  // return <>{data}</>
  const users = await getUser('772403255@qq.com');
  return <>{users[0].id}</>;
}